<!DOCTYPE html>
<html>
<head>
	<title></title>
	<!--[if lt IE 9]>
	<meta http-equiv="refresh" content="0;ie.html" />
	<![endif]-->

	<link rel="shortcut icon" href="__STATIC__/layout/favicon.ico"> <link href="__STATIC__/layout/css/bootstrap.min.css?v=3.3.6" rel="stylesheet">
	<link href="__STATIC__/layout/css/font-awesome.min.css?v=4.4.0" rel="stylesheet">
	<link href="__STATIC__/layout/css/animate.css" rel="stylesheet">
	<link href="__STATIC__/layout/css/style.css?v=4.1.0" rel="stylesheet">
	<link href="__STATIC__/layout/css/channel.css?v=4.1.0" rel="stylesheet">
	<script src="__STATIC__/layout/js/jquery.min.js"></script>
	<!-- Sweet Alert -->
	<link href="__STATIC__/layout/css/plugins/sweetalert/sweetalert.css" rel="stylesheet">
	<!-- Sweet alert -->
	<script src="__STATIC__/layout/js/plugins/sweetalert/sweetalert.min.js"></script>
	<!-- layer javascript -->
	<script src="__STATIC__/layout/js/plugins/layer/layer.min.js"></script>

	<script src="__STATIC__/layout/js/plugins/suggest/bootstrap-suggest.min.js"></script>
</head>
<body class="white-bg" style="color:#333;padding:3px;">

<div class="ibox" style="padding: 10px">
			<div class="ibox-content">
				<form role="form" id="formadd" method="post" action="{:url('add')}">
				<div class="row form-group">
					<label class="col-xs-3 control-label">城市名称:</label>
					<div class="col-xs-9">
						<input name="title" id="title" type="text" placeholder="城市名称" class="form-control" value="">
					</div>
				</div>
				<div class="row form-group">
					<label class="col-xs-3 control-label">所属城市:</label>
					<div class="col-xs-7">
						<div class="input-group">
							<input name="city" id="testNoBtn" type="text" placeholder="所属城市" class="form-control" value="">
							<div class="input-group-btn">
								<button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown">
									<span class="caret"></span>
								</button>
								<ul class="dropdown-menu dropdown-menu-right" role="menu">
								</ul>
							</div>
						</div>
					</div>
					<div class="col-xs-2">
						<a href="javascript:;" class="btn btn-default" id="select">选择</a>
					</div>
				</div>
				<div class="row">
					<div class="col-xs-12" style="text-align: center;padding: 20px 0">
						<input class="btn btn-sm btn-primary" type="submit" id="tijiao" value="提 交">

					</div>
				</div>
			</form>
		</div>

</div>

</body>
</html>
<script>
    $(function () {
		//
        $('body').on('click','#tijiao',function () {
            var form =  $('#formadd')
            var title =  $('#title').val()
            var city =  $('#testNoBtn').data('id')
            $.ajax({
                'type':'post',
                'url':form.attr('action'),
                'data':{title:title,city:city},
                'dataType':'json',
                'success':function (data) {
                    if(data.success){
                        swal({
                            title: data.msg,
                            type: "success"
                        },function(){
                            parent.location.reload()
						});

                    }else
                        swal({
                            title: data.msg,
                            type: "warning"
                        });
                }
            })
			return false
        })

        /**
         * 测试(首次从 URL 获取数据，显示 header，不显示按钮，忽略大小写，可清除)
         */
        $("#testNoBtn").bsSuggest({
            url: "{:url('provicejson')}",
            /*effectiveFields: ["userName", "shortAccount"],
            searchFields: [ "shortAccount"],*/
            effectiveFieldsAlias:{title: "城市名称"},
            ignorecase: true,
            showHeader: true,
            showBtn: false,     //不显示下拉按钮
            delayUntilKeyup: true, //获取数据的方式为 firstByUrl 时，延迟到有输入/获取到焦点时才请求数据
            idField: "id",
            keyField: "title",
            clearable: true
        }).on('onDataRequestSuccess', function (e, result) {
            console.log('onDataRequestSuccess: ', result);
        }).on('onSetSelectValue', function (e, keyword, data) {
            console.log('onSetSelectValue: ', keyword, data);
        }).on('onUnsetSelectValue', function () {
            console.log("onUnsetSelectValue");
        });

//        选择省份
        $('#select').on('click',function () {
            var index = parent.layer.getFrameIndex(window.name)
            //iframe层-父子操作
            parent.layer.open({
                type: 2,
                title: '请选择省份',
                area: ['500px', '400px'],
                fixed: false, //不固定
                maxmin: true,
                content: '{:url("selectprovice")}?frameindex='+index
            });
            return false

        })

    })
</script>